<template>
  <a-modal
    :title="title"
    :visible="sharePictuVisible"
    :confirm-loading="confirmLoading"
    @cancel="cancel"
    @ok="ok"
  >
  
  <a-form-model ref="editsharePictuModel"  :model="sharePictuFormDatas"  layout="vertical" 
  :labelCol="{span: 8}" :wrapperCol="{span: 16}">
      <a-form-model-item label="上传图片" prop="image">
        <upImages :url.sync="sharePictuFormDatas.image"></upImages>
      </a-form-model-item>
      <a-form-model-item label="状态" >
        <a-radio-group v-model="sharePictuFormDatas.status">
          <a-radio :value="1"> 正常 </a-radio>
          <a-radio :value="0"> 禁用 </a-radio>
        </a-radio-group>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
import { editSharePictureListApi,addSharePictureListApi } from '@/api/brand.js'
export default {
  data() {
    return {
      sharePictuVisible:false,
      title:"添加",
      confirmLoading:false,
      loading:false,

      sharePictuFormDatas:{
        ids:"",
        is_free:0,
        money:"0.00",
        title:'',
        image:"",
        status:1,
      },
      editSharePicturerules:{
      }
    }
  },
  created() {
  },
  methods: {
    openeditShareimgs(json){
      this.sharePictuFormDatas={
        ids:"",
        is_free:0,
        money:"0.00",
        title:'',
        image:"",
        status:1,
      }
        this.title='添加'
      if(json){
        this.title='修改信息'
        this.sharePictuFormDatas=JSON.parse(JSON.stringify(json))
        this.sharePictuFormDatas.ids=json.id
      }
      this.sharePictuVisible=true
    },
    handleOk(){
      this.sharePictuVisible=false
    },
    cancel(){
      this.handleOk()
    },
    ok(){
      this.$refs.editsharePictuModel.validate(valid => {
        if (valid) {
          if(this.sharePictuFormDatas.ids){
            this.editLists()
          }else{
            this.addsLists()
          }
        }
      })
    },

    editLists(){
      editSharePictureListApi({...this.sharePictuFormDatas,
        brand_id: process.env.VUE_APP_BRAND_ID}).then(res=>{
          this.$message.success("操作成功");
        this.handleOk()
        this.$emit("changes")
      })
    },
    addsLists(){
      addSharePictureListApi({...this.sharePictuFormDatas,
        brand_id: process.env.VUE_APP_BRAND_ID}).then(res=>{
          this.$message.success("操作成功");
        this.handleOk()
        this.$emit("changes")
      })
    }



  }
}
</script>

<style lang="less" scoped>
</style>
